from time import sleep
from selenium.webdriver.common.by import By
from selenium import  webdriver
import pytest
class TestOA:
    @pytest.fixture()
    def get_driver(self):
        driver=webdriver.Firefox()
        driver.get("http://192.168.1.138/ranzhi/www/sys/index.html")
        yield driver
        driver.quit()
    testdata=[("admin","123456","签退"),
              ("","123456","登录失败，请检查您的成员名或密码是否填写正确。"),
              ("admin","","登录失败，请检查您的成员名或密码是否填写正确。"),
              ("adminininininn","","登录失败，请检查您的成员名或密码是否填写正确。")
              ]

    @pytest.mark.parametrize("username,password,expect",testdata)
    @pytest.mark.run(order=3)
    def test_login(self,get_driver,username,password,expect):
        try:
            driver=get_driver
            sleep(2)
            driver.maximize_window()
            driver.find_element(By.XPATH, '/html/body/div/div[1]/div[1]/div/div/button').click()
            driver.find_element(By.XPATH, '/html/body/div/div[1]/div[1]/div/div/ul/li[1]/a').click()
            sleep(1)
            driver.find_element("id","account").send_keys(username)
            driver.find_element("id","password").send_keys(password)
            driver.find_element("id","submit").click()
            text=driver.find_element("LINK_TEXT","签退").text
            assert text == expect ,"登录失败"
        except AssertionError as e:
            raise e
        except Exception as e:
            print(e)
            raise e
